package com.ruoyi.course.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.course.dto.OffDay;

/**
 * 课程时间对象 lab_course_timetable
 * 
 * @author jun.wang
 * @date 2022-04-05
 */
public class LabCourseTimetable extends BaseEntity {
	private static final long serialVersionUID = 1L;
	public static ObjectMapper mapper = new ObjectMapper();
	private JavaType javaType = mapper.getTypeFactory().constructParametricType(ArrayList.class, OffDay.class);
	/** 主键 */
	private Long timetableId;

	/** 课表名称 */
	@Excel(name = "课表名称")
	private String courseName;

	/** 课表起始日期 */
	@JsonFormat(pattern = "yyyy-MM-dd")
	@Excel(name = "课表起始日期", width = 30, dateFormat = "yyyy-MM-dd")
	private Date courseStartDate;

	/** 课表结束日期 */
	@JsonFormat(pattern = "yyyy-MM-dd")
	@Excel(name = "课表结束日期", width = 30, dateFormat = "yyyy-MM-dd")
	private Date courseEndDate;
	/** 课表结束日期 */
	@JsonFormat(pattern = "yyyy-MM-dd")
	private Date lastDate;

	private String createName;
	private String updateName;
	/**学年*/
	private String xn;
	/**学期*/
	private String xq;
	
	
	public String getXn() {
		return xn;
	}

	public void setXn(String xn) {
		this.xn = xn;
	}

	public String getXq() {
		return xq;
	}

	public void setXq(String xq) {
		this.xq = xq;
	}

	private List<OffDay> courseOffDayList;

	public List<OffDay> getCourseOffDayList() {
		if (courseOffDayList == null && this.getRemark() != null) {
			try {
				this.courseOffDayList = mapper.readValue(this.getRemark(), javaType);
			} catch (JsonMappingException e) {
				e.printStackTrace();
			} catch (JsonProcessingException e) {
				e.printStackTrace();
			}
		}
		if (courseOffDayList == null) {
			courseOffDayList = new ArrayList<OffDay>();
			courseOffDayList.add(new OffDay());
		}
		return courseOffDayList;
	}

	public String getRemarkValue() {
		if (this.getCourseOffDayList() != null) {
			StringBuffer StrBuffer = new StringBuffer();
			for (OffDay day : this.courseOffDayList) {
				if (day.getName() != null)
					StrBuffer.append(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, day.getDate()))
							.append("(" + day.getName() + ");");
			}
			return StrBuffer.toString();
		}
		return "";
	}

	public void setCourseOffDayList(List<OffDay> courseOffDayList) {
		this.courseOffDayList = courseOffDayList;
	}

	public String getCreateName() {
		return createName;
	}

	public void setCreateName(String createName) {
		this.createName = createName;
	}

	public String getUpdateName() {
		return updateName;
	}

	public void setUpdateName(String updateName) {
		this.updateName = updateName;
	}

	public void setTimetableId(Long timetableId) {
		this.timetableId = timetableId;
	}

	public Long getTimetableId() {
		return timetableId;
	}

	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

	public String getCourseName() {
		return courseName;
	}

	public void setCourseStartDate(Date courseStartDate) {
		this.courseStartDate = courseStartDate;
	}

	public Date getCourseStartDate() {
		return courseStartDate;
	}

	public void setCourseEndDate(Date courseEndDate) {
		this.courseEndDate = courseEndDate;
	}

	public Date getCourseEndDate() {
		return courseEndDate;
	}
	
	

	public Date getLastDate() {
		return lastDate;
	}

	public void setLastDate(Date lastDate) {
		this.lastDate = lastDate;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("timetableId", getTimetableId())
				.append("courseName", getCourseName()).append("courseStartDate", getCourseStartDate())
				.append("courseEndDate", getCourseEndDate())
				.append("createBy", getCreateBy())
				.append("createTime", getCreateTime()).append("updateBy", getUpdateBy())
				.append("updateTime", getUpdateTime()).toString();
	}
}
